package main;

import javax.microedition.lcdui.Graphics;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author chau
 */
public class FlyString extends ShortShowObject {

    public static final int FLY_HORIZONTAL = 1;
    public static final int FLY_VERTICAL = 2;
    private int flyType;
    private String textShow = "";
    private int textX;
    private int textY;
    private int deltaMove;
    private int limitHorizontal;
    private int textColor;
    private int count;

    public FlyString(int type, int color) {
        this.flyType = type;
        textColor = color;
    }

    public void setText(String text, int deltaMove, int x, int y) {
        if (text != null) {
            this.textShow = text;
        }
        this.deltaMove = deltaMove;
        this.textX = x;
        this.textY = y;
        count = 0;
    }

    public void setLimitHorizontal(int limit) {
        this.limitHorizontal = limit;
    }

    public void setTextColor(int color) {
        this.textColor = color;
    }

    public void paintObject(Graphics g) {
        PiPoDesigner.drawString(g, textShow, PiPoDesigner.COLOR_BLACK, textColor, textX, textY);
    }

    public void doLoop() {
        if (isShow) {
            if (flyType == FLY_VERTICAL) {
                textY -= deltaMove;
            } else {
                textX -= deltaMove;
                if (textX < -PiPoDesigner.stringWidth(textShow)) {
                    textX = limitHorizontal;
                    count++;
                    if (count == 2) {
                        isShow = false;
                    }
                }
            }
        }
    }

    public void doWhenStop() {
    }
}
